fix(test): jest.resetModules in freeUtxos bot test to clear cached real impl#270
Open
QSchlegel wants to merge 1 commit into
Open
fix(test): jest.resetModules in freeUtxos bot test to clear cached real impl#270QSchlegel wants to merge 1 commit into
QSchlegel wants to merge 1 commit into
Conversation
When freeUtxos.bot.test.ts runs in the full suite, three cases that
exercise the canonical-scriptCbor fallback in resolveWalletScriptAddress
fail intermittently — decodeNativeScriptFromCbor is never observed as
called and the error path produces "unknown error" instead of the
mocked message. In isolation the same tests pass.
Root cause: nativeScriptUtils.test.ts imports the real
@/utils/nativeScriptUtils (no mock), caching the module in Jest's
registry. By the time this suite declares its jest.mock(..., {virtual:
true}) replacement, the bindings inside the transitively imported
@/lib/server/walletScriptAddress are already wired to the real
implementation, so the mocks never fire.
jest.resetModules() in beforeAll forces the dynamic handler import to
walk a fresh module graph that honours this suite's mocks. Verified
with `npx jest` (full suite): 357 pass / 0 fail / 2 skipped.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The `checks` job on #229 failed with 3 flakes in `src/tests/freeUtxos.bot.test.ts`:
In isolation (`jest src/tests/freeUtxos.bot.test.ts`) all 4 tests pass. In the full suite, those 3 fail.
Root cause
`src/tests/nativeScriptUtils.test.ts` imports the real `@/utils/nativeScriptUtils` (no mock) and Jest caches it in the module registry. When `freeUtxos.bot.test.ts` runs later, its top-level `jest.mock("@/utils/nativeScriptUtils", () => …, { virtual: true })` doesn't re-wire the bindings inside the transitively imported `@/lib/server/walletScriptAddress` — those bindings already point at the real implementation. The mocks never fire, the real `decodeNativeScriptFromCbor` is invoked on the test fixture `"canonical-cbor"`, throws a non-Error, and the handler returns "unknown error".
Fix
A single `jest.resetModules()` in `beforeAll` before the dynamic handler import forces a fresh module graph that honors this suite's mocks.
Verification
```
$ npx jest
Test Suites: 1 skipped, 46 passed, 46 of 47 total
Tests: 2 skipped, 357 passed, 359 total
```
(was 1 failed / 3 tests failing before the fix)
🤖 Generated with Claude Code